AI Lessons
Lesson 27: Retaining history in chat

Purpose: To understand why an LLM has no memory between requests, and how sending conversation history creates context.

No. of Classes

1 - (Time : 1 hour 30 minutes, Laptops/desktops : 10, Students strength : 15 to 20).

Materials Required

Laptop / Desktop with Internet connections / Wi-Fi.

Prior knowledge
  • JSON objects
  • Arrays and Array operations
  • System prompts and roles
Exercises

Exercise (1)



  • Ask an LLM a follow-up question without sending history ('What is the capital of India?' then 'How many people live there?') and observe that it loses the thread.

Exercise (2)



  • Store the conversation in an array and send the full message list with each request, then repeat the same follow-up and compare.

Solutions



Teacher's Instruction:
  1. Explain that LLM APIs are stateless (they have no built-in memory of past requests), meaning every new prompt is treated as a completely fresh interaction.
  2. Guide Exercise 1 to show how asking ambiguous follow-ups (like "How many people live there?") fails when isolated from prior turns.
  3. Demonstrate Exercise 2 by maintaining an array of messages, appending both user prompts and assistant replies before sending the entire thread to the API payload.